package com.wiscamp.ninechapters.panels.infrastructure.mappers;

import com.wiscamp.ninechapters.panels.infrastructure.views.ApplicationView;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
public interface ApplicationViewMapper extends JpaRepository<ApplicationView, Long>, JpaSpecificationExecutor<ApplicationView> {

    @Query(value = "select p from ApplicationView p where p.applicationCode = :appCode")
    ApplicationView findByApplicationCode(String appCode);

    @Query(value = "select p from ApplicationView p where p.applicationName = :appName")
    Collection<ApplicationView> findListByApplicationName(String appName);

    @Query(value = "select p from ApplicationView p where p.applicationGroup = :appGroup")
    Collection<ApplicationView> findListByApplicationGroup(String appGroup);

    @Query(value = "select p from ApplicationView p where p.enabled = true")
    Collection<ApplicationView> findListByAvailable();

    Page<ApplicationView> findAll(Specification<ApplicationView> specification, Pageable pageable);
}
